package com.iwhalecloud.bss.kite.cucc.service.util;

import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.reception.ICustReceptionService;
import com.iwhalecloud.bss.kite.cucc.client.dto.cust.CuccContextCustDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.scene.CuccCustInfoDetailDTO;
import com.iwhalecloud.bss.kite.cucc.service.cache.CuccCustInfoDetailCache;
import com.ztesoft.bss.common.util.SpringUtil;

import java.util.Objects;

public class CustInfoUtils {

    public static CuccContextCustDTO getCustInfo(String custId, String provinceNbr, String custState) {
        CuccContextCustDTO contextCust = new CuccContextCustDTO();
        CuccCustInfoDetailDTO cuccCustInfoDTO = null;

        ICustReceptionService custReceptionService = SpringUtil.getBean(ICustReceptionService.class);
        //云联网国际业务客户详情接口
        if(!KiteStringUtils.isEmpty(provinceNbr) && provinceNbr.startsWith("48") || provinceNbr.startsWith("49")){
            cuccCustInfoDTO = custReceptionService.getCustomerInfoNewForNational(custId);
        }else {
            cuccCustInfoDTO = custReceptionService.getCustomerInfoNew(custId);
        }

        if (Objects.nonNull(cuccCustInfoDTO)) {
            KiteBeanUtils.copyProperties(cuccCustInfoDTO, contextCust);
            contextCust.setProvinceCode(cuccCustInfoDTO.getProvinceCode());
            contextCust.setCustName(cuccCustInfoDTO.getCustName());
            contextCust.setLanId(cuccCustInfoDTO.getCityCode());
            contextCust.setRegionId(cuccCustInfoDTO.getBcityCode());
            contextCust.setCustType(cuccCustInfoDTO.getCustClassType());
            contextCust.setBbssCustId(cuccCustInfoDTO.getBbssCustId());
            contextCust.setCbssId(cuccCustInfoDTO.getCustId());
            contextCust.setAttrs(cuccCustInfoDTO.getAttrs());
            contextCust.setFirstCallingTypeCode(cuccCustInfoDTO.getFirstCallingTypeCode());
            contextCust.setCustState(custState);
        }
        CuccCustInfoDetailCache.put(custId, cuccCustInfoDTO);
        return contextCust;
    }
}
